﻿using JetBrains.Annotations;
using System;
using System.ComponentModel.DataAnnotations;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Validation;
using Xms.Abp.Data;
using Xms.Abp.Domain;

namespace IdentityManagement
{
    [MultiTenancyHostSide]
    public class IdentityClaimType : AggregateRoot<Guid>, IHasName<Guid>
    {
        [Required]
        [DynamicMaxLength(typeof(IdentityClaimTypeConsts), nameof(IdentityClaimTypeConsts.MaxNameLength))]
        public virtual string Name { get; set; }

        public virtual bool Required { get; set; }

        public virtual bool IsStatic { get; protected set; }

        [DynamicMaxLength(typeof(IdentityClaimTypeConsts), nameof(IdentityClaimTypeConsts.MaxRegexLength))]
        public virtual string Regex { get; set; }

        [DynamicMaxLength(typeof(IdentityClaimTypeConsts), nameof(IdentityClaimTypeConsts.MaxRegexDescriptionLength))]
        public virtual string RegexDescription { get; set; }

        [DynamicMaxLength(typeof(IdentityClaimTypeConsts), nameof(IdentityClaimTypeConsts.MaxDescriptionLength))]
        public virtual string Description { get; set; }

        public virtual IdentityClaimValueType ValueType { get; set; }

        protected IdentityClaimType()
        {

        }

        public IdentityClaimType(
            Guid id,
            [NotNull] string name,
            bool required = false,
            bool isStatic = false,
            [CanBeNull] string regex = null,
            [CanBeNull] string regexDescription = null,
            [CanBeNull] string description = null,
            IdentityClaimValueType valueType = IdentityClaimValueType.String)
        {
            Id = id;
            SetName(name);
            Required = required;
            IsStatic = isStatic;
            Regex = regex;
            RegexDescription = regexDescription;
            Description = description;
            ValueType = valueType;
        }

        public void SetName([NotNull] string name)
        {
            Name = Check.NotNull(name, nameof(name));
        }
    }
}
